package com.lb.statck.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lb.statck.mapper.category.ProductMapper;
import com.lb.statck.mapper.codeMapper;
import com.lb.statck.mapper.order.OrderMapper;
import com.lb.statck.pojo.dto.codeDto;
import com.lb.statck.pojo.vo.OrderVo;
import com.lb.statck.pojo.vo.ProductVo;
import com.lb.statck.pojo.vo.codeVo;
import com.lb.statck.service.codeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.UUID;

@Service
public class codeServiceimpel extends ServiceImpl<codeMapper, codeVo> implements codeService  {
   @Autowired
   private codeMapper codeMapper;
   @Autowired
   private ProductMapper productMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public String insertOrder(codeDto codeDto) {
        LocalDateTime now = LocalDateTime.now();
        QueryWrapper<codeVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", codeDto.getId());
        codeVo codeVo = codeMapper.selectOne(queryWrapper);
    //    QueryWrapper<ProductVo> queryWrapper1 = new QueryWrapper<>();
    //    queryWrapper.eq("product_code",codeVo.getProductCode());
       // codeVo codeVo = codeMapper.selectOne(queryWrapper);
    //  productMapper.selectOne(queryWrapper1);

        String data = now.toString();
        String randomOrderNumber = UUID.randomUUID().toString().replace("-", "");
        String payOrder=data;
        payOrder = payOrder.replaceAll("[^0-9]", "");
        OrderVo orderVo = new OrderVo();
        orderVo.setUserid(codeDto.getUserid());
        orderVo.setPrice(codeVo.getPrice());
        orderVo.setPayorderid(payOrder);
        orderVo.setStatus(0);
        orderVo.setCreatetime(LocalDateTime.now());
        orderVo.setProduct_code(codeVo.getProductCode());
        orderMapper.inserts(orderVo);
        return payOrder;
    }
}
